package com.shiikong_memory.yez.Arknights.ArknightsData;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
public class AccountData {
    //游戏名
    private String name;
    //游戏id
    private String uid;
    //游戏等级
    private Integer level;
    //注册时间
    private Date registerTs;
    //签名
    private String resume;
    //干员数量
    private Integer agentSize;
    //角色数量
    private Integer skinSize;
    //精二干员数量
    private Integer evolvePhase2Size = 0;
    //满级模组数量
    private Integer equipMaxSize = 0;


    public AccountData(JSONObject json) {
        JSONObject status = json.getJSONObject("status");
        name = status.getString("name");
        uid = status.getString("uid");
        level = status.getInteger("level");
        registerTs = new Date(status.getLong("registerTs")*1000L);
        resume = status.getString("resume");
        JSONArray chars = json.getJSONArray("chars");
        agentSize = chars.size()-2;
        JSONObject charsData;
        for(int i=0;i<chars.size();i++){
            charsData = chars.getJSONObject(i);
            if (charsData.getInteger("evolvePhase") == 2) {
                if ("char_002_amiya".equals(charsData.getString("charId"))) evolvePhase2Size-=2;
                evolvePhase2Size++;
            }
            JSONArray equip = charsData.getJSONArray("equip");
            for (int j = 0; j< equip.size(); j++){
                if (equip.getJSONObject(j).getInteger("level") == 3) equipMaxSize++;
            }
        }
        JSONArray skins = json.getJSONArray("skins");
        skinSize = skins.size();
    }

    public AccountData(String statusData, String charsData1, String skinsData){
        JSONObject status = JSON.parseObject(statusData);
        name = status.getString("name");
        uid = status.getString("uid");
        level = status.getInteger("level");
        registerTs = new Date(status.getLong("registerTs")*1000L);
        resume = status.getString("resume");
        JSONArray chars = JSON.parseArray(charsData1);
        agentSize = chars.size()-2;
        JSONObject charsData;
        for(int i=0;i<chars.size();i++){
            charsData = chars.getJSONObject(i);
            if (charsData.getInteger("evolvePhase") == 2) {
                if ("char_002_amiya".equals(charsData.getString("charId"))) evolvePhase2Size-=2;
                evolvePhase2Size++;
            }
            JSONArray equip = charsData.getJSONArray("equip");
            for (int j = 0; j< equip.size(); j++){
                if (equip.getJSONObject(j).getInteger("level") == 3) {
                    equipMaxSize++;
                }
            }
        }
        JSONArray skins = JSON.parseArray(skinsData);
        skinSize = skins.size();
    }


}
